﻿/***************************************************************************
 *		ElGee Google Chart API Helper
 *		Copyright(C) 2011 by Laurent Geffroy lgeffroy@gmail.com
 * 
 *		This program is free software; you can redistribute it and/or 
 *		modify it under the terms of the GNU General Public License as
 *		published by the Free Software Foundation; either version 2 of 
 *		the License, or (at your option) any later version.
 *		
 *		This program is distributed WITHOUT ANY WARRANTY; without even the
 *		implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 *		See the GNU General Public License for more details.
 *	
 *      For particular licensing, please contact me at lgeffroy@gmail.com
 *****************************************************************************/


using System;
using System.Text;

namespace ElGee.Google.Charts
{
    /// <summary>
    /// Axis Class
    /// </summary>
    public class Axis
    {
        /// <summary>
        /// Gets or sets the direction.
        /// The direction in which the values along the axis grow. Will be Specified -1 (Reversed) to reverse the order of the values.
        /// </summary>
        /// <value>direction</value>
        public TypeOfDirection Direction { get; set; }

        /// <summary>
        /// Gets or sets the text position.
        /// Position of the axis text, relative to the chart area. Supported values: 'out', 'in', 'none'.
        /// </summary>
        /// <value>textPosition</value>
        public TypeOfPosition TextPosition { get; set; }

        /// <summary>
        /// Gets or sets the text style.
        /// An object that specifies the axis text style. The object has this format: {color: <string>, fontName: <string>, fontSize: <number>}
        /// </summary>
        /// <value>The text style.</value>
        public FontWithColor TextStyle { get; set; }

        /// <summary>
        /// Gets or sets the title.
        /// property that specifies the title of the  axis.
        /// </summary>
        /// <value>title</value>
        public String Title { get; set; }

        /// <summary>
        /// Gets or sets the title text style.
        /// An object that specifies the axis text style. The object has this format: {color: <string>, fontName: <string>, fontSize: <number>}
        /// </summary>
        /// <value>titleTextStyle</value>
        public FontWithColor TitleTextStyle { get; set; }

        /// <summary>
        /// Gets a value indicating whether this instance is empty.
        /// </summary>
        /// <value><c>true</c> if this instance is empty; otherwise, <c>false</c>.</value>
        public virtual bool IsEmpty
        {
            get
            {
                if ((Direction == TypeOfDirection.Reverse) && ((TextPosition == TypeOfPosition.In) || (TextPosition == TypeOfPosition.None))
                    && (!TextStyle.IsEmpty) && (!String.IsNullOrWhiteSpace(Title)) && (!TitleTextStyle.IsEmpty))
                    return false;

                return true;
            }
        }


        /// <summary>
        /// Initializes a new instance of the <see cref="Axis"/> class.
        /// </summary>
        public Axis()
        {
            Direction = TypeOfDirection.Normal;
            TextPosition = TypeOfPosition.Undefined;
            TextStyle = new FontWithColor();
            TitleTextStyle = new FontWithColor();
        }

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public virtual string ToString()
        {
            if (IsEmpty)
                return String.Empty;

            var sb = new StringBuilder();
            if (Direction == TypeOfDirection.Reverse)
                sb.Append("direction: -1,");

            if ((TextPosition != TypeOfPosition.Out) && (TextPosition != TypeOfPosition.Undefined))
                sb.Append("textPosition: '").Append(TextPosition.ToString().ToLower()).Append("',");

            if (!TextStyle.IsEmpty)
                sb.Append("textStyle: {").Append(TextStyle.ToString()).Append("},");

            if (!String.IsNullOrWhiteSpace(Title))
                sb.Append("title: '").Append(Title).Append("',");

            if (!TitleTextStyle.IsEmpty)
                sb.Append("titleTextStyle: {").Append(TitleTextStyle.ToString()).Append("},");

            // Removing the last comma
            sb.Remove(sb.Length - 1, 1);

            return sb.ToString();
        }
    }
}
